import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from "@/views/Login";
import UploadFiles from "@/components/UploadFiles";
import LoginPage from "@/views/Login";
import homeRouter from "./home/home"
import Home from '@/views/Home';

Vue.use(VueRouter)

const routes = [
    homeRouter,
    {
        path: '/',
        name: 'Login',
        component: Login
    },
    {
        path: '/home',
        name: 'Home',
        component: Home
    },
    {
        path: '/upload',
        name: 'UploadFiles',
        component: UploadFiles,
        redirect: '/login',//重定向，刚进入时进入登录页
    },
    {
        path: '/login',
        name: 'Login',
        component: LoginPage
    },
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

// router.beforeEach((to, from, next) => {
//     console.log(to);
//     // 判断路径是否是登录页
//     if (to.path === '/login') {
//         // 是登录页，执行下一步
//         next();
//     } else {
//         // 不是登录页，判断本地有无 token
//         let token = sessionStorage.getItem('token');
//         if (token === null || token === ' ') {
//             // token 为空或不存在，跳转到登录页
//             next('/login');
//         } else {
//             next();
//         }
//     }
// })

export default router